/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.*;

/**
 *
 * @author Scott
 */
public class UserPreference {

    static int[] itemids = new int[50];
    static int userid;
    static double[] preferences = new double[50];
    static int[] customers;

    public UserPreference(int[] itemids, int userid, double[] preferences) {
    }

    static String readFile(String path, Charset encoding)
            throws IOException {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return encoding.decode(ByteBuffer.wrap(encoded)).toString();
    }

    public static void main(String args[]) throws FileNotFoundException, UnsupportedEncodingException, IOException, ParseException {
        String content = readFile("C:\\\\Users\\\\Scott\\\\Documents\\\\NetBeansProjects\\\\trunk\\\\DataMining\\\\src\\\\UserItem.txt", StandardCharsets.UTF_8);
        int counter = 0;
        int counter2 = 0;//Index Array's

        String[] ContentSplitLine = content.split("\\n");

        for (String n : ContentSplitLine) {

            String[] ContentSplit = n.split(",");

            for (String m : ContentSplit) {
                if (counter == 0) {
                    userid = Integer.parseInt(m);
                    counter++;
                } else if (counter == 1) {
                    itemids[0] = Integer.parseInt(m);
                    counter++;
                } else {
                    Float f = new Float(m);
                    preferences[counter2] = f.doubleValue();

                    counter = 0;
                    counter2++;
                    if (counter2 == itemids.length) {
                        vergrootItemsid(itemids, counter2);
                        vergrootPreferences(preferences, counter2);
                    }
                }
                System.out.println(m + " ");
            }


        }
        System.out.println("ItemsID Length:" + itemids.length);
        System.out.println("Preferences Length:" + preferences.length);
        // Create a tree map 
        TreeMap tm = new TreeMap();
// Put elements to the map 
//        tm.put(itemids, preferences);
        tm.put("John Doe", new Double(3434.34));
        tm.put("Tom Smith", new Double(123.22));
        tm.put("Jane Baker", new Double(1378.00));
        tm.put("Todd Hall", new Double(99.22));
        tm.put("Ralph Smith", new Double(-19.08));
//        // Get a set of the entries 
        Set set = tm.entrySet();
//// Get an iterator 
        Iterator i = set.iterator();
//// Display elements 
        while (i.hasNext()) {
            Map.Entry me = (Map.Entry) i.next();
            System.out.print(me.getKey() + ": ");
            System.out.println(me.getValue());
        }
        System.out.println();
// Deposit 1000 into John Doe's account 
        double balance = ((Double) tm.get("John Doe")).doubleValue();
        tm.put("John Doe", new Double(balance + 1000));
        System.out.println("John Doe's new balance: "
                + tm.get("John Doe"));
    }

    private static void vergrootItemsid(int[] copyFrom, int counter2) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        
        int Arraysize;
        Arraysize = counter2 + 3;
        itemids = new int[Arraysize];
        System.arraycopy(copyFrom, 0, itemids, 0, copyFrom.length);
    }

    private static void vergrootPreferences(double[] copyFrom, int counter2) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }
}
